package com.igeek.blog_parent_test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.blog_parent_test.entity.Comments;
import com.igeek.blog_parent_test.entity.Users;
import com.igeek.blog_parent_test.mapper.CommentsMapper;
import com.igeek.blog_parent_test.service.ICommentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.igeek.blog_parent_test.vo.PageQueryVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-04
 */
@Service
public class CommentsServiceImpl extends ServiceImpl<CommentsMapper, Comments> implements ICommentsService {

    @Transactional(readOnly = true)
    @Override
    public Page<Comments> findPage(PageQueryVO vo) {
        Integer currentPage = vo.getCurrentPage();
        Integer pageSize = vo.getPageSize();
        Page<Comments> page = Page.of(currentPage, pageSize);

        String queryString = vo.getQueryString();
        LambdaQueryWrapper<Comments> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StringUtils.hasLength(queryString),Comments::getCommentId,queryString)
                .or()
                .like(StringUtils.hasLength(queryString),Comments::getContent,queryString);
        Page<Comments> commentsPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
        return commentsPage;
    }

    @Override
    public boolean del(Integer commentId) {
        return false;
    }
}
